import java.util.Scanner;  
  
public class DiskManager {  
    private Disk disk;  
    private Scanner scanner;  
  
    public DiskManager(Disk disk) {  
        this.disk = disk;  
        scanner = new Scanner(System.in);  
    }  
  
    public void run() {  
        while (true) {  
            System.out.println("1. Allocate block");  
            System.out.println("2. Deallocate block");  
            System.out.println("3. Exit");  
            System.out.print("Enter your choice: ");  
            int choice = scanner.nextInt();  
            switch (choice) {  
                case 1:  
                    allocateBlock();  
                    break;  
                case 2:  
                    deallocateBlock();  
                    break;  
                case 3:  
                    System.exit(0);  
                default:  
                    System.out.println("Invalid choice.");  
            }  
        }  
    }  
  
    private void allocateBlock() {  
        int x, y;  
        do {  
            System.out.print("Enter the x-coordinate of the block: ");  
            x = scanner.nextInt();  
            System.out.print("Enter the y-coordinate of the block: ");  
            y = scanner.nextInt();  
        } while (disk.isFree(x, y));  
        disk.allocate(x, y);  
        System.out.println("Block allocated successfully.");  
    }  
  
    private void deallocateBlock() {  
        int x, y;  
        do {  
            System.out.print("Enter the x-coordinate of the block: ");  
            x = scanner.nextInt();  
            System.out.print("Enter the y-coordinate of the block: ");  
            y = scanner.nextInt();  
        } while (!disk.isFree(x, y));  
        disk.deallocate(x, y);  

    }  
}